package controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns="/ApplicationServlet")
public class ApplicationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public ApplicationServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置请求编码
        request.setCharacterEncoding("UTF-8");
        // 获取 ServletContext
        String appName = (String) getServletContext().getAttribute("appName");
        System.out.println("appName: " + appName);
        // 输出到客户端
        response.getWriter().println("<html><body>");
        if (appName != null) {
            response.getWriter().println("<h1>应用名称：" + appName + "</h1>");
        } else {
            response.getWriter().println("<h1>未找到应用名称</h1>");
        }
        response.getWriter().println("</body></html>");
	}

}
